package net.lab1024.sa.admin.module.business.supercomputer.sendtask;

import lombok.extern.slf4j.Slf4j;
import net.lab1024.sa.admin.module.business.supercomputer.datatask.dao.DatataskDao;
import net.lab1024.sa.admin.module.business.supercomputer.datatask.domain.entity.DatataskEntity;
import net.lab1024.sa.admin.module.business.supercomputer.sqlgenerator.domain.vo.SqlTextVO;
import net.lab1024.sa.admin.module.business.supercomputer.sqlgenerator.service.SqlGeneratorService;
import net.lab1024.sa.base.module.support.job.core.SmartJob;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.IOException;
@Slf4j
@Service
public class SendInitiation implements SmartJob {
    @Resource
    DatataskDao datataskDao;
    @Resource
    SqlGeneratorService sqlGeneratorService;
    @Override
    public String run(String param) {

        //从Task获取发送的地址和SQL数据
        DatataskEntity task = datataskDao.selectById(param);
        SqlTextVO sql;
        //TaskId从发送参数获得SQL
        try {
            sql = sqlGeneratorService.getSQL(task.getDataSourceId());
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        //发送数据的API
        System.out.println(
                "目的地址"+task.getTaskId()+
                "Source:"+sql.getSink()+
                "Sink:"+sql.getSource()

        );
        return "数据发送成功";
    }
}
